package Memory;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wangyg6 on 2018/7/10.
 * 常量池oom
 * 无法做到占用空间
 * @VM args : -XX:PermSize=10M -XX:MaxPermSize=10M
 * -XX:MaxMetaspaceSize=128m jdk1.8
 * @see String#intern()
 * {@link String#intern()}
 */
public class ConstantOutOfMemory {
	public static void main(String[] args) throws Exception {
		try {
			List<String> strings = new ArrayList<String>();
			int i = 0;
			while (true) {
				strings.add(String.valueOf(i++).intern());
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
	}
}